home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / catrom2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-22  |  720 b   |  35 lines

  1. #include "proctext.h"
  2. #include "noise.h"
  3.  
  4. float
  5. catrom2(float d)
  6. {
  7. #define SAMPRATE 100  /* table entries per unit distance */
  8. #define NENTRIES (4*SAMPRATE+1)
  9.     float x;
  10.     int i;
  11.     static float table[NENTRIES];
  12.     static int initialized = 0;
  13.  
  14.     if (d >= 4)
  15.         return 0;
  16.  
  17.     if (!initialized) {
  18.         for (i = 0; i < NENTRIES; i++) {
  19.             x = i/(float) SAMPRATE;
  20.             x = (float)sqrt((double)x);
  21.             if (x < 1)
  22.                 table[i] = 0.5 * (2+x*x*(-5+x*3));
  23.             else
  24.                 table[i] = 0.5 * (4+x*(-8+x*(5-x)));
  25.         }
  26.         initialized = 1;
  27.     }
  28.  
  29.     d = d*SAMPRATE + 0.5;
  30.     i = FLOOR(d);
  31.     if (i >= NENTRIES)
  32.         return 0;
  33.     return table[i];
  34. }
  35.